package com.heima.jopo.web;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.utilconn.GetConn;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UpdateInfo {

    public UserInfo selectInfo(int id) {

        Connection conn = GetConn.getConn();

        String sql = "select * from t_user_info where id=?";

        try {
            PreparedStatement ps = conn.prepareStatement(sql);

            ps.setInt(1, id);
            ResultSet resultSet = ps.executeQuery();

            UserInfo userInfo = new UserInfo();
            while (resultSet.next()) {
                userInfo.setId(resultSet.getInt("id") + "");
                userInfo.setPhone(resultSet.getString("phone"));
                userInfo.setPasswrod(resultSet.getString("passwrod"));
                userInfo.setUsername((resultSet.getString("username")));
                userInfo.setSex(resultSet.getString("sex"));
                userInfo.setBirthday(resultSet.getString("birthday"));
                userInfo.setCareer(resultSet.getString("career"));

            }
            return userInfo;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return null;
    }
}
